﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;


namespace DataAccess
{
    public class FireGroupData
    {
        public bool AddFire(int groupID,int fireSourece,string fireDscrb)
        {
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "FireGroupAdd";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@GroupID", DbType.Int32, groupID);
            database.AddInParameter(dbCommand, "@FireSource", DbType.Int32, fireSourece);
            database.AddInParameter(dbCommand, "@FireDscrb", DbType.AnsiString, fireDscrb);            
            database.ExecuteDataSet(dbCommand);
            int returnValue = int.Parse(database.GetParameterValue(dbCommand, "@AffectRows").ToString());
            return returnValue > 0 ? true : false; 
        }
        public DataTable GetLastGroup()
        {
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "FireGroupGetLast";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            dt = database.ExecuteDataSet(dbCommand).Tables[0];
            return dt;      
        }
        public bool UpdateStatus(string hospitalStatus,string stationStatus)        
        {
            bool isOK = false;
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "FireGroupStatusUpdate";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@hosipitalST", DbType.String, hospitalStatus);
            database.AddInParameter(dbCommand, "@stationST", DbType.String, stationStatus);
            database.ExecuteNonQuery(dbCommand);
            string value=database.GetParameterValue(dbCommand, "@AffectRows").ToString();
            if (value != null)
            {
                isOK = true;
            }
            return isOK;
        }
        public bool HasNewCall(int typeCode)
        {
            bool hasNew = false;
            DataTable dt = new DataTable();
            Database database = DatabaseFactory.CreateDatabase();
            string sqlCommand = "FireGroupNew";
            DbCommand dbCommand = database.GetStoredProcCommand(sqlCommand);
            database.AddOutParameter(dbCommand, "@AffectRows", DbType.Int32, 10);
            database.AddInParameter(dbCommand, "@RoleID", DbType.Int32, typeCode);            
            //database.ExecuteNonQuery(dbCommand);
            dt = database.ExecuteDataSet(dbCommand).Tables[0];
            //string value = database.GetParameterValue(dbCommand, "@AffectRows").ToString();
            if (dt.Rows.Count != 0)
            {
                hasNew = true;
            }
            return hasNew;
        }

    }
}
